import axios from 'axios'
import store from '@/store'
import router from '@/router'

let request = axios.create({
    // baseURL: '/api',
    baseURL: 'http://82.156.30.240:8888/api/private/v1',
    // baseURL: 'http://127.0.0.1:8888/api/private/v1',
    timeout: 6800
})
//请求拦截
request.interceptors.request.use((config) => {
    
    config.headers.Authorization = store.getters.token
    return config

}, (err) => {

    return Promise.reject(err)

})
//响应拦截
request.interceptors.response.use((response) => {
    let arrstatus = [200,201,204]
    if (response.data.meta.msg == '无效token') {
        store.commit('user/REM_TOKEN')
        router.push('/login')
    }
    // else if(arrstatus.includes(response.data.meta.status)){
    //     this.$message.success(response.data.meta.msg)
    // }else{
    //     this.$message.error(response.data.meta.msg)
    // }
    return response.data

}, (err) => {
    return Promise.reject(err)
})

// 导出axios实例
export default request